# -*- coding: utf-8 -*-

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5 import Qt
import sys

class lineEditDemo(QWidget):
    def __init__(self, parent=None):
        super(lineEditDemo, self).__init__(parent)
        self.setWindowTitle("VegeTable Admin")
        self.setAttribute(Qt.Qt.WA_TranslucentBackground)
        self.setWindowFlags(Qt.Qt.FramelessWindowHint | Qt.Qt.Tool | Qt.Qt.WindowStaysOnTopHint)
        with open('./main.qss', 'r') as f:
            self.setStyleSheet(f.read())
        flo = QFormLayout()
        pNormalLineEdit = QLineEdit()
        pNoEchoLineEdit = QLineEdit()
        pPasswordLineEdit = QLineEdit()
        pPasswordEchoOnEditLineEdit = QLineEdit()
        mainbtn = QPushButton('Button1')
        flo.addRow("Normal", pNormalLineEdit)
        flo.addRow("NoEcho", mainbtn)
        flo.addRow("Password", pPasswordLineEdit)
        flo.addRow("PasswordEchoOnEdit",pPasswordEchoOnEditLineEdit)

        pNormalLineEdit.setPlaceholderText("Normal")
        pNoEchoLineEdit.setPlaceholderText("NoEcho")
        pPasswordLineEdit.setPlaceholderText("Password")
        pPasswordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoEdit")

        # 设置显示效果
        pNormalLineEdit.setEchoMode(QLineEdit.Normal)
        pNoEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
        pPasswordLineEdit.setEchoMode(QLineEdit.Password)
        pPasswordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)

        self.setLayout(flo)
    def mouseMoveEvent(self, e: QMouseEvent): # 重写移动事件
        self._endPos = e.pos() - self._startPos
        self.move(self.pos() + self._endPos)
    def mousePressEvent(self, e: QMouseEvent):
        if e.button() == Qt.Qt.LeftButton:
            self._isTracking = True
            self._startPos = QPoint(e.x(), e.y())
    def mouseReleaseEvent(self, e: QMouseEvent):
        if e.button() == Qt.Qt.LeftButton:
            self._isTracking = False
            self._startPos = None
            self._endPos = None

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = lineEditDemo()
    win.show()
    
    w=win
    tp = QSystemTrayIcon(w)
    tp.setIcon(QIcon('./logo.ico'))
    # 设置系统托盘图标的菜单
    a1 = QAction('&显示', triggered=w.show)
    def quitApp():
        w.show()
        re = QMessageBox.question(w, "提示", "是否退出VegeTable Admin?", QMessageBox.Yes |
                                  QMessageBox.No, QMessageBox.No)
        if re == QMessageBox.Yes:
            QCoreApplication.instance().quit()
            tp.setVisible(False)
    a2 = QAction('&退出', triggered=quitApp)  # 直接退出可以用qApp.quit
    tpMenu = QMenu()
    tpMenu.addAction(a1)
    tpMenu.addAction(a2)
    tp.setContextMenu(tpMenu)
    tp.show()
    tp.showMessage('VegeTable Admin', '成功运行', icon=0)
    def clickMessage():
        print("信息被点击了")
    tp.messageClicked.connect(clickMessage)
    def act(reason):
        if reason == 2 or reason == 3:
            w.show()
    tp.activated.connect(act)
    
    sys.exit(app.exec_())